***********************************************
* Learning to Fight Together Replication Data *
* Michael A. Morgan and Daniel S. Morey       *
* Created 06/09/2024                          *
* Updated 07/27/2024                          *
***********************************************

*** All analyses were completed using STATA 17 ***
*** ESTOUT package was installed to create post-test estimates ***

********************
* CHANGE DIRECTORY *
********************
cd "C:\Users\Michael\OneDrive - marietta.edu\Morgan - Professional Development\Article - Learning to Fight Together\Updated Datasets\Source Data"

****************
* OPEN DATASET *
****************
use "Learning to Fight Together Dataset (06-09-2024).dta", clear

******************************************
* FIGURE 1: COMBINED GRAPH UNAMA/MINURSO *
******************************************
*** Operational Experience During MINURSO ***
keep if missionid==25
sort coalition
tsset time
drop if year>2019
* Remove cases of two contributor states or less
drop in 184/205 
label variable time "Mission-Months"
label variable dyadexp "Operational Experience"
twoway (tsline dyadexp, lpattern(dash)), ytitle(`"Operational Experience"') xtitle(`"Mission-Months"') title(`"UNAMA"')
graph save Graph "Operational Experience UNAMA.gph", replace
clear all
use "Learning to Fight Together Dataset (06-09-2024).dta", clear

*** Operational Experience During MINURSO ***
keep if missionid==13
sort coalition
tsset time
drop if year>2019
label variable time "Mission-Months"
label variable dyadexp "Operational Experience"
twoway (tsline dyadexp, lpattern(dash)), ytitle(`"Operational Experience"') xtitle(`"Mission-Months"') title(`"MINURSO"')
graph save Graph "Operational Experience MINURSO.gph", replace
clear all
use "Learning to Fight Together Dataset (06-09-2024).dta", clear

graph combine "Operational Experience UNAMA.gph" "Operational Experience MINURSO.gph"
graph save Graph "Figure 1 - Combined Experience Graph.gph", replace

*****************************************************
* TABLE 1: COALITION EXPERIENCE AND CIVILIAN DEATHS *
*****************************************************
clear all
use "Learning to Fight Together Dataset (06-09-2024).dta", clear

xtset missionid
xtnbreg deaths_civilians dyadexplag, fe
estimates store m1, title(Model 1)
xtnbreg deaths_civilians dyadexplag troopslag2 policelag2 observerslag2 deaths_civilianslag2, fe
estimates store m2, title(Model 2)
xtnbreg deaths_civilians dyadexplag troopslag2 policelag2 observerslag2 deaths_civilianslag2 difpcaplag2 difvdemlag2 partnerslag2, fe
estimates store m3, title(Model 3)
xtnbreg deaths_civilians dyadexplag troopslag2 policelag2 observerslag2 deaths_civilianslag2 difpcaplag2 difvdemlag2 partnerslag2 battledeaths_lag2 tpop_log, fe
estimates store m4, title(Model 4)
xtnbreg deaths_civilians dyadexplag troopslag2 policelag2 observerslag2 deaths_civilianslag2 difpcaplag2 difvdemlag2 partnerslag2 battledeaths_lag2 tpop_log time time2 time3, fe
estimates store m5, title(Model 5)

estout m1 m2 m3 m4 m5, cells(b(star fmt(8)) se(par fmt(8))) starlevels (* 0.10 ** 0.05 *** 0.01)   ///
legend label varlabels(_cons constant)               ///
stats(N ll chi2 aic bic, fmt(%9.0g %9.3f) label(N LogLikelihood Chi2 AIC BIC))

************************************************************************
* FIGURE 2: MARGINAL EFFECT OF COALITION EXPERIENCE ON CIVILIAN DEATHS *
************************************************************************
xtset missionid
xtnbreg deaths_civilians dyadexplag troopslag2 policelag2 observerslag2 deaths_civilianslag2 difpcaplag2 difvdemlag2 partnerslag2 battledeaths_lag2 tpop_log time time2 time3, fe
margins, atmeans at(dyadexplag=(0 (12) 120))
marginsplot,recast(line) recastci(rarea) title("Adjusted Predictions with 95% CIs") xtitle("Coalition Experience") ytitle("Predicted Civilian Deaths")
graph save Graph "Figure 2 - ME Coalition Experience Civilian Deaths.gph", replace

*****************************************************
* TABLE 2: ROBUSTNESS TESTS OF COALITION EXPERIENCE *
*****************************************************
xtset missionid

*** ALTERNATIVE MEASURE ***
xtnbreg deaths_civilians explag troopslag2 policelag2 observerslag2 deaths_civilianslag2 difpcaplag2 difvdemlag2 partnerslag2 battledeaths_lag2 tpop_log time time2 time3, fe
estimates store m6, title(Alternative Measure)

*** LAST 12 MONTHS OF MISSION ***
xtnbreg deaths_civilians dyadexplag troopslag2 policelag2 observerslag2 deaths_civilianslag2 difpcaplag2 difvdemlag2 partnerslag2 battledeaths_lag2 tpop_log time time2 time3 if last12!=1, fe
estimates store m7, title(End of Mission)

*** OUTLIERS ***
xtnbreg deaths_civilians dyadexplag troopslag2 policelag2 observerslag2 deaths_civilianslag2 difpcaplag2 difvdemlag2 partnerslag2 battledeaths_lag2 tpop_log time time2 time3 if dyadexplag<82.674, fe
estimates store m8, title(Outliers)

*** CUMULATIVE EXPERIENCE ***
xtnbreg deaths_civilians cexp_lag troopslag2 policelag2 observerslag2 deaths_civilianslag2 difpcaplag2 difvdemlag2 partnerslag2 battledeaths_lag2 tpop_log time time2 time3, fe
estimates store m9, title(Cumulative Experience)

estout m6 m7 m8 m9, cells(b(star fmt(8)) se(par fmt(8))) starlevels (* 0.10 ** 0.05 *** 0.01) legend label varlabels(_cons constant) stats(N ll chi2 aic bic, fmt(%9.0g %9.3f) label(N LogLikelihood Chi2 AIC BIC))